﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using QuickApp.Core;
using Resto.CostControl.Core;
using QuickApp.MVCControl;

namespace Resto.CostControl.Web.Controllers
{
    public class StorageController : Controller
    {
        private readonly IRepository<Storage> _Repo;
        private readonly IUnitOfWork _UnitOfWork;

        public StorageController(IRepository<Storage> repo, UnitOfWork unitOfWork)
        {
            _Repo = repo;
            _UnitOfWork = unitOfWork;
        }

        public ActionResult Index(string type)
        {
            ViewBag.Title = type == "RawMaterial" ? "原材料库存" : "半成品库存";
            ViewBag.Type = type;
            return View();
        }

        [HttpPost]
        public JsonResult List(string type, DWZPageInfo pageInfo, DWZQueryModel where)
        {
            where.AddItem("Type", type);
            var list = _Repo.GetPageable(pageInfo.ToPageInfo(), where);
            var fdata = pageInfo.ToFlexiGridData<Storage>(list.Page.ToList(), list.Total);
            return Json(fdata);
        }
    }
}
